from sklearn.feature_selection import f_regression, SelectKBest
import pandas as pd


def FRegression(inputs, targets, k=3):
    model = SelectKBest(f_regression, k=k)
    new_features = model.fit_transform(inputs, targets)
    support = model.get_support()

    return new_features, support


def init_data():
    files = ['dataset/raw_data/春天.xlsx', 'dataset/raw_data/夏天.xlsx', 'dataset/raw_data/秋天.xlsx',
             'dataset/raw_data/冬天.xlsx']
    results = ['春.xlsx', '夏.xlsx', '秋.xlsx', '冬.xlsx']
    jijie = ['Sheet1']
    for i, r in zip(files, results):
        print(i)
        dff = pd.ExcelWriter('dataset/data/%s' % r)
        for sheet in jijie:
            df = pd.read_excel(i, sheet_name=sheet)
            df['date'] = pd.to_datetime(df.time).dt.strftime("%Y-%m-%d %H:%M:%S")
            mean_value = df.groupby('date').mean() / 10
            d1, d2, d3, d4, label = mean_value.空气温度, mean_value.十分风速, mean_value.湿度, mean_value.气压, mean_value.TA_CU,
            d_result = pd.concat([d1, d2, d3, d4, label], axis=1)
            if '季' in sheet:
                sheet = "self"
            d_result = d_result.dropna()
            d_result.to_excel(dff, sheet_name=sheet)

        dff.save()
